package com.zhuchenhua.drugmanagementsystem.activity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;

import com.zhuchenhua.drugmanagementsystem.R;
import com.zhuchenhua.drugmanagementsystem.database.DrugsDAO;

import java.util.List;
import java.util.Map;

public class QueryDrugsActivity extends AppCompatActivity {
    //定义组件
    ListView listView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_query_books);
        setTitle("查看记录");
        //初始化界面
        initView();
    }

    public void initView() {
        //建立数据库访问对象
        DrugsDAO dao = new DrugsDAO(getApplicationContext());
        //打开数据库
        dao.open();
        //调用数据库访问方法
        List<Map<String,Object>> mOrderData = dao.getAllDrugs();
        //获取组件
        listView = (ListView) findViewById(R.id.lst_orders);
        //定义数据源
        String[] from={"id","name","department","drugNum"};
        //定义布局控件ID
        int[] to={R.id.tv_lst_id,R.id.tv_lst_name,R.id.tv_lst_department,R.id.tv_lst_drugNum};
        SimpleAdapter listItemAdapter = new SimpleAdapter(QueryDrugsActivity.this,mOrderData,R.layout.item_list,from,to);
        //添加并显示
        listView.setAdapter(listItemAdapter);
        //关闭数据库
        dao.close();
    }
}
